﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BusinessLayer.WorldArtPrice.Entities;
using DBHelper;

namespace BusinessLayer.WorldArtPrice
{
    public class SlideShowDetailBL
    {
        private readonly DbHelper _db;

        public SlideShowDetailBL()
        {
            _db = new DbHelper(new DbConfig().DbWorldArtPriceConnectionString);         
        }

        public List<SlideShowDetail> GetBySlideShowId(int slideShowId)
        {
            var oCommand = new SqlCommand("sp_SlideShowDetail_Select_By_SlideShowId") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@SlideShowId", slideShowId));

            var list = _db.GetList<SlideShowDetail>(oCommand);
            return list;
        }

        public SlideShowDetail GetById(int id)
        {
            var oCommand = new SqlCommand("sp_SlideShowDetail_Select_By_Id") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@Id", id));

            var list = _db.GetList<SlideShowDetail>(oCommand);
            return list.FirstOrDefault();
        }

        public void Insert(SlideShowDetail slideShowDetail)
        {
            var oCommand = new SqlCommand("sp_SlideShowDetail_Insert") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@SlideShowId", slideShowDetail.SlideShowId));
            oCommand.Parameters.Add(new SqlParameter("@Image", slideShowDetail.Image));
            oCommand.Parameters.Add(new SqlParameter("@ImageUrl", slideShowDetail.ImageUrl));
            oCommand.Parameters.Add(new SqlParameter("@RedirectUrl", slideShowDetail.RedirectUrl)); 
            
            _db.ExecuteNonQuery(oCommand);
        }

        public void DeleteBySlideShowId(int slideShowId)
        {
            var oCommand = new SqlCommand("sp_SlideShowDetail_DeleteBySlideShowId") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@SlideShowId", slideShowId));

            _db.ExecuteNonQuery(oCommand);
        }
    }
}
